﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Quanlytruongtruongtieuhoc
{
    public partial class frmInmatkhau : Form
    {
        public frmInmatkhau()
        {
            InitializeComponent();
        }

        private void frmInmatkhau_Load(object sender, EventArgs e)
        {
            try
            {
                if (frmQuanlynguoidung.loai == 1)
                {
                    clsKetnoi.taoKetnoi();
                    SqlDataAdapter ap = new SqlDataAdapter("select a.ma_gv,a.ho,a.ten,b.mat_khau from giao_vien a,tam b where a.ma_gv=b.nguoi_dung and a.xoa='False'", clsKetnoi.con);
                    dtMatkhau sv = new dtMatkhau();
                    ap.Fill(sv.dataTableMatkhau);
                    crpInmatkhau rp = new crpInmatkhau();
                    rp.SetDataSource(sv);
                    xemMatkhau.ReportSource = rp;
                }
                else if (frmQuanlynguoidung.loai == 2)
                {
                    clsKetnoi.taoKetnoi();
                    if (frmQuanlynguoidung.taikhoan == "")
                    {
                        MessageBox.Show("Chưa nhập tài khoản cần in.", "Thông tin", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    }
                    else
                    {
                        SqlDataAdapter ap = new SqlDataAdapter("select a.ma_gv,a.ho,a.ten,b.mat_khau from giao_vien a,tam b where a.ma_gv=b.nguoi_dung and a.ma_gv='" + frmQuanlynguoidung.taikhoan + "'", clsKetnoi.con);
                        dtMatkhau sv = new dtMatkhau();
                        ap.Fill(sv.dataTableMatkhau);
                        crpInmatkhau rp = new crpInmatkhau();
                        rp.SetDataSource(sv);
                        xemMatkhau.ReportSource = rp;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
